package xyz.xtt.asset.service;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import com.baomidou.mybatisplus.extension.service.IService;

import xyz.xtt.asset.api.enums.DealStateEnum;
import xyz.xtt.asset.api.enums.SellPatternEnum;
import xyz.xtt.asset.client.request.TransferActionRequest;
import xyz.xtt.asset.client.response.TransferFromResponse;
import xyz.xtt.asset.entity.TblAsset;
import xyz.xtt.asset.entity.TblAssetAccount;
import xyz.xtt.asset.entity.TblAssetTransaction;
import xyz.xtt.asset.enums.OrderTypeEnum;
import xyz.xtt.asset.enums.PayUnitEnum;
import xyz.xtt.asset.request.GiftRequest;
import xyz.xtt.asset.response.TransactionResponse;
import xyz.xtt.asset.vo.HotTopAssetVo;

/**
 * <p>
 * 资产交易记录表 服务类
 * </p>
 *
 * @author author
 * @since 2024-10-28
 */
public interface ITblAssetTransactionService extends IService<TblAssetTransaction> {
	/**
	 * 查询支付中订单
	 * 
	 * @param buyUserId
	 * @param keySet
	 * @param state
	 * @return
	 */
	List<TblAssetTransaction> queryPaySync(String buyUserId, Set<String> keySet, DealStateEnum state);

	/**
	 * 订单查询
	 *
	 * @param buyUserId
	 * @param orderId
	 * @return
	 */
	List<TblAssetTransaction> queryPaySync(String buyUserId, Long orderId);

	/**
	 * 订单查询
	 *
	 * @param buyUserId
	 * @param orderId
	 * @return
	 */
	TblAssetTransaction queryPaySyncOne(String buyUserId, Long orderId);

	/**
	 * 更新支付单的状态
	 *
	 * @param buyUserId
	 * @param orderNo
	 * @param tradeNo
	 * @param targetAssetIds
	 * @param oldState
	 * @param newState
	 * @return
	 */
	boolean updateBuyOrderState(String buyUserId, String orderNo, String tradeNo, Collection<Long> targetAssetIds, DealStateEnum oldState,
			DealStateEnum newState);

	/**
	 * 更新交易记录的状态
	 *
	 * @param buyUserId
	 * @param orderId
	 * @param orderNo
	 * @param tradeNo
	 * @param oldState
	 * @param newState
	 * @return
	 */
	boolean updateSingleOrderState(String buyUserId, Long orderId, String orderNo, String tradeNo, DealStateEnum oldState, DealStateEnum newState);

	/**
	 * 更新交易记录的支付状态
	 *
	 * @param buyUserId
	 * @param orderId
	 * @param orderNo
	 * @param tradeNo
	 * @param oldState
	 * @param newState
	 * @return
	 */
	boolean updateSinglePayState(String buyUserId, Long orderId, String orderNo, String tradeNo, DealStateEnum oldState, DealStateEnum newState);

	/**
	 * 取消其它人订单
	 * 
	 * 除也购买成功的人以外的取消掉
	 * 
	 * @param buyUserId
	 * @param targetAssetIds
	 * @param oldState
	 * @param newState
	 * @return
	 */
	boolean cacelOrder(String buyUserId, Collection<Long> targetAssetIds, DealStateEnum oldState, DealStateEnum newState);

	/**
	 * 交易历史
	 * 
	 * @param uid
	 * @param type
	 * @param currPage
	 * @param pageSize
	 * @return
	 */
	List<TransactionResponse> transaction(String uid, String type, Integer currPage, Integer pageSize);

//	/**
//	 * 构建交易对像
//	 * 
//	 * @param asset
//	 * @param buyerUserId
//	 * @param dealState
//	 * @param orderType
//	 * @param sellPattern
//	 * @param amount
//	 * @param orderNo
//	 * @return
//	 */
//	TblAssetTransaction buildTransaction(TblAsset asset, String buyerUserId, DealStateEnum dealState, OrderTypeEnum orderType, SellPatternEnum sellPattern,
//			BigDecimal amount, String orderNo);

//	/**
//	 * 构建交易对像
//	 *
//	 * @param asset
//	 * @param buyerUserId
//	 * @param dealState
//	 * @param orderType
//	 * @param sellPattern
//	 * @param amount
//	 * @param orderNo
//	 * @param fees
//	 * @return
//	 */
//	TblAssetTransaction buildTransaction(TblAsset asset, String buyerUserId, DealStateEnum dealState, OrderTypeEnum orderType, SellPatternEnum sellPattern,
//			BigDecimal amount, String orderNo, BigDecimal fees);

	/**
	 * 活动类的交易单
	 * 
	 * @param from
	 * @param to
	 * @param amount
	 * @param orderNo
	 * @param orderPirce
	 * @param bizType
	 * @return
	 */
	TblAssetTransaction buildTransactionActivity(TblAssetAccount from, TblAssetAccount to, Integer amount, String orderNo, BigDecimal orderPirce,
			String bizType);

	/**
	 * 构建交易对像
	 *
	 * @param asset
	 * @param buyerUserId
	 * @param dealState
	 * @param orderType
	 * @param sellPattern
	 * @param amount
	 * @param orderNo
	 * @param fees
	 * @param orderPrice
	 * @param bizType
	 * @return
	 */
	TblAssetTransaction buildTransaction(TblAsset asset, String buyerUserId, DealStateEnum dealState, OrderTypeEnum orderType, SellPatternEnum sellPattern,
			BigDecimal amount, String orderNo, BigDecimal fees, BigDecimal orderPrice, BigDecimal actTotalPrice, String bizType);

	/**
	 * 交易记录
	 * 
	 * @param from
	 * @param to
	 * @param num
	 * @param orderNo
	 * @param orderType
	 * @param dealState
	 * @param price
	 * @param unit
	 * @return
	 */
	TblAssetTransaction buildTransaction(TblAssetAccount from, TblAssetAccount to, Integer num, String orderNo, OrderTypeEnum orderType,
			DealStateEnum dealState, BigDecimal price, PayUnitEnum unit, BigDecimal orderPirce, String bizType);

	TblAssetTransaction buildTransaction(TblAssetAccount from, Long toUserId, Integer num, String orderNo, OrderTypeEnum orderType, DealStateEnum dealState,
			BigDecimal price, PayUnitEnum unit, BigDecimal orderPirce, String bizType);

	/**
	 * @param orderNo
	 * @return
	 */
	TblAssetTransaction infoWithOrderNo(String orderNo);

	/**
	 * 查之前的交易单
	 * 
	 * @param buyUid
	 * @param assetId
	 * @return
	 */
	TblAssetTransaction beforeTransactionWithBuyUidAndAssetId(Long buyUid, Long assetId);

	/**
	 * 查询交易单
	 * 
	 * @param id
	 * @param from
	 * @param to
	 * @return
	 */
	TblAssetTransaction queryTblAssetTransaction(Long id, Long from, Long to);

	/**
	 * 根据id更新交易单状态
	 *
	 * @param id
	 * @param actTotalPrice
	 * @return
	 */
	Boolean upateTransactionDealState(Long id, Long from, Long to, DealStateEnum oldDealSate, DealStateEnum newDealSate, BigDecimal actTotalPrice);

	Boolean upateTransactionDealState(Long id, DealStateEnum oldDealSate, DealStateEnum newDealSate);

	/**
	 * 查询未支付状态订单
	 * 
	 * @param assetId 资产id
	 * @param buyerId 购买者id
	 * @return 订单
	 */
	TblAssetTransaction queryNotPayOrder(Long assetId, long buyerId);

	/**
	 * @param assetId
	 * @param buyerId
	 * @param OrderType
	 * @return
	 */
	TblAssetTransaction queryTransaction(Long assetId, String buyerId, OrderTypeEnum orderType);

	/**
	 * mul
	 * 
	 * @param transferActionRequest
	 * @return
	 */
	TblAssetTransaction queryTransaction(TransferActionRequest transferActionRequest);

	TblAssetTransaction queryNotPaiedPersonalMintUpChaninOrder(Long assetId, String uid);

	/**
	 * 某人购买指定商品的历史最高成交价
	 * 
	 * @param uid
	 * @param goodsId
	 * @return
	 */
	BigDecimal buyMaxPriceWithHistory(String uid, String goodsId);

	/**
	 * 热卖榜， 临时处理
	 * 
	 * @return
	 */
	List<HotTopAssetVo> getHotTopList();

	TblAssetTransaction transactionInfo(Long orderId);

	TransferFromResponse gift(Long uid, GiftRequest giftRequest);


	/**
	 *  根据订单号 查询交易单
	 * @param orderNo
	 * @param form
	 * @param to
	 * @return
	 */
	TblAssetTransaction queryTransaction(String orderNo, Long form, Long to);

	/**
	 *  根据资产id 查询铸造交易信息
	 * @param assetId
	 * @return
	 */
	TblAssetTransaction queryTransactionByAssetId(Long assetId);
}
